package org.elsfs.cloud.common.mybatis.ext.sql.support.condition;

import lombok.RequiredArgsConstructor;
import org.elsfs.cloud.common.util.lang.NamingCase;

/**
 * 子查询范围条件
 *
 */
@RequiredArgsConstructor
public class InSubQueryConditionItem implements ConditionItem {

    /**
     * 左边字段名称
     */
    protected final String leftField;
    /**
     * 子查询SQL
     */
    protected final String inSql;

    /**
     * 构建SQL片段
     *
     * @return SQL片段
     */
    @Override
    public String buildSqlFragment() {
        return String.format(
            "%s IN (%s)",
            NamingCase.toUnderlineCase(this.leftField),
            this.inSql
        );
    }
}
